//
//  WATFSettingHeadView.swift
//  WiFiFaster
//
//  Created by one on 2023/12/28.
//

import UIKit

class WATFSettingHeadView: UICollectionReusableView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(watf_titleLabel)
        addSubview(watf_upView)
        addSubview(watf_speedView)
        addSubview(watf_hotView)
        watf_titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(35)
            make.centerX.equalToSuperview()
            make.height.equalTo(35)
        }
        watf_upView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 114, height: 46))
            make.right.equalTo(self.snp.centerX).offset(-18)
            make.top.equalTo(watf_titleLabel.snp.bottom).offset(34)
        }
        watf_speedView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 114, height: 46))
            make.left.equalTo(self.snp.centerX).offset(18)
            make.top.equalTo(watf_titleLabel.snp.bottom).offset(34)
        }
        watf_hotView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 18, height: 20))
            make.left.equalTo(watf_upView.snp.left).offset(8)
            make.centerY.equalTo(watf_upView.snp.top)
        }
        watf_updateStateView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - watf action
    func watf_updateStateView() {
        let watf_spCount = WATFManager.watf_manager.watf_getIntValue(watf_key: watf_speedModel?.watf_title ?? "")
        let watf_upCount = WATFManager.watf_manager.watf_getIntValue(watf_key: watf_upModel?.watf_title ?? "")
        if watf_upCount >= watf_spCount {
            watf_hotView.snp.remakeConstraints { make in

                make.size.equalTo(CGSize(width: 18, height: 20))
                make.left.equalTo(watf_upView.snp.left).offset(8)
                make.centerY.equalTo(watf_upView.snp.top)
            }
            return
        }
        watf_hotView.snp.remakeConstraints { make in
            make.size.equalTo(CGSize(width: 18, height: 20))
            make.left.equalTo(watf_speedView.snp.left).offset(8)
            make.centerY.equalTo(watf_speedView.snp.top)
        }
       
    }
    @objc func watf_speedClick() {
        
        (watf_viewGetVController as? WATFBaseViewController)?.watf_funcClickModel(watf_funcModel: watf_speedModel)
    }
    @objc func watf_speedUpClick() {
        (watf_viewGetVController as? WATFBaseViewController)?.watf_funcClickModel(watf_funcModel: watf_upModel)
    }
    // MARK: - watf lazy
    var watf_speedModel = WATFManager.watf_manager.watf_funcModels.first
    var watf_upModel = WATFManager.watf_manager.watf_funcModels.first { watf_funcModel in
        return watf_funcModel.watf_type == .watf_speedUP
    }
    lazy var watf_titleLabel: UILabel = {
        let watf_titleLabel = UILabel()
        watf_titleLabel.textColor = .white
        watf_titleLabel.font = UIFont.systemFont(ofSize: 18)
        watf_titleLabel.text = "WiFi Faster"
        return watf_titleLabel
    }()
    lazy var watf_upView: UIButton = {
        let watf_upView = UIButton()
        watf_upView.setBackgroundImage(UIImage(named: "watf_setting_up"), for: .normal)
        watf_upView.addTarget(self, action: #selector(watf_speedUpClick), for: .touchUpInside)
        return watf_upView
    }()
    lazy var watf_speedView: UIButton = {
        let watf_speedView = UIButton()
        watf_speedView.setBackgroundImage(UIImage(named: "watf_setting_speed"), for: .normal)
        watf_speedView.addTarget(self, action: #selector(watf_speedClick), for: .touchUpInside)
        return watf_speedView
    }()
    lazy var watf_hotView: UIImageView = {
        let watf_hotView = UIImageView(image: UIImage(named: "watf_setting_hot"))
        return watf_hotView
    }()
}
